package com.ruoyi.common.utils;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @program: spring-boot-demo
 * @date: 2021/7/15 17:59
 * @description: 属性文件获取
 **/
@Component
public class PropertiesUtil {

    @Autowired
    private Environment environment;
    private static Environment env;

    //PostConstruct注解不可以有参数的
    @PostConstruct
    public void init(){
        env = this.environment;
    }

    public static String getString(String key){
        if(env != null){
            String value = env.getProperty(key);
            return value;
        }
        return "";
    }

}
